using System;
using System.Linq;
using System.Net.Sockets;
using Newtonsoft.Json;
using Console = Colorful.Console;

namespace ReactiveListUnitTest.Entities
{
    public class Person : Entity
    {
        public Name Name
        {
            get => DataContext.Names.FirstOrDefault(Name => Name.Id == __Name);

            set
            {
                __Name = value.Id;
                if (!DataContext.Names.Any(item => item.Id == __Name)) DataContext.Names.Add(value);
            }
        }

        protected String __Name { get; set; }


        public Byte Age { get; set; }
        public String Addr { get; set; }
        public Boolean IsBoy { get; set; }
        public Contacts Contacts
        {
            get => DataContext.Contactses.FirstOrDefault(Contacts => Contacts.Id == __Contacts);
            set
            {
                __Contacts = value.Id;
                if (!DataContext.Contactses.Any(item => item.Id == __Contacts)) DataContext.Contactses.Add(value);
            }
        }
        protected String __Contacts { get; set; }
        public Company Company
        {
            get => DataContext.Companies.FirstOrDefault(Company => Company.Id == __Company);
            set
            {
                __Company = value.Id;
                if (!DataContext.Companies.Any(item => item.Id == __Company)) DataContext.Companies.Add(value);
            }
        }
        protected String __Company { get; set; }
        public override string Id { get; set; } = Guid.NewGuid().ToString();
    }
}